﻿using System;
using System.Collections.Generic;
using Model.ModelEventArgs;

namespace Model.NotifyingCollections
{
    public class NotifyingStringList : List<string>
    {
        public event EventHandler<StringEventArgs> AddedItemEvent;
        public event EventHandler<StringEventArgs> RemovedItemEvent;

        public new void Add(string item)
        {
            base.Add(item);
            if (AddedItemEvent != null)
                AddedItemEvent(this, new StringEventArgs {Body = item});
        }

        public new bool Remove(string item)
        {
            var result = base.Remove(item);
            if (result && RemovedItemEvent != null)
                RemovedItemEvent(this, new StringEventArgs {Body = item});
            return result;
        }

        public new void RemoveAt(int index)
        {
            var item = base[index];
            base.RemoveAt(index);
            if (RemovedItemEvent != null)
                RemovedItemEvent(this, new StringEventArgs{Body = item});
        }
    }
}
